#include "AlgebraicDifference.h"

QRgb AlgebraicDifference::__doOperation (QRgb c1, QRgb c2)
{
	unsigned int r1, g1, b1;
	double a1 = (double)qAlpha (c1) / 255.0;
	double a2 = (double)qAlpha (c2) / 255.0;

	if (a1 * qRed (c1) > a2 * qRed (c2))
		r1 = a1 * qRed (c1) - a2 * qRed (c2);
	else
		r1 = a2 * qRed (c2) - a1 * qRed (c1);

	if (a1 * qGreen (c1) > a2 * qGreen (c2))
		g1 = a1 * qGreen (c1) - a2 * qGreen (c2);
	else
		g1 = a2 * qGreen (c2) - a1 * qGreen (c1);

	if (a1 * qBlue (c1) > a2 * qBlue (c2))
		b1 = a1 * qBlue (c1) - a2 * qBlue (c2);
	else
		b1 = a2 * qBlue (c2) - a1 * qBlue (c1);

	c1 = qRgba (r1, g1, b1, qAlpha (c1));
	return __super::__doOperation (c1, c2);
}

AlgebraicDifference::AlgebraicDifference () : AlgebraicOperation ("Difference")
{

}
